package com.gtt.lazy.controller;

import java.util.List;

import com.gtt.lazy.domain.Category;
import com.gtt.lazy.service.CategoryService;

/**
 * 类别管理Action
 * 
 * @author 高甜甜
 * @date 2009-7-9
 */
public class CategoryAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private CategoryService categoryService;

	private List<Category> results;
	private Category cat;

	private int id;
	private String name;
	private String desc;

	public String list() {
		// 确定所要显示的页数
		if (page == 0)
			page = 1;
		int start = (page - 1) * Constant.SIZE;
		results = categoryService.list(start, Constant.SIZE);
		setPagination(categoryService.count(), Constant.SIZE, page);
		return SUCCESS;
	}

	public String toAdd() {
		return SUCCESS;
	}

	public String add() {
		categoryService.add(new Category(name, desc));
		return SUCCESS;
	}

	public String toMod() {
		cat = categoryService.get(id);
		return SUCCESS;
	}

	public String mod() {
		Category category = new Category(name, desc);
		category.setId(id);
		categoryService.update(category);
		return SUCCESS;
	}

	public String del() {
		categoryService.delete(id);
		return SUCCESS;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public List<Category> getResults() {
		return results;
	}

	public Category getCat() {
		return cat;
	}

	public void setCat(Category cat) {
		this.cat = cat;
	}

	public void setResults(List<Category> results) {
		this.results = results;
	}

	public CategoryService getCategoryService() {
		return categoryService;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

}
